<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.List"%>
<%@ page import="com.jack.bookshop.vo.PageVo"%>
<%@ page import="com.jack.bookshop.vo.BookVo"%>
<%@ page import="com.jack.bookshop.dao.BookDao"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page isELIgnored="false" %>

<%
    PageVo<BookVo> pageVo = (PageVo<BookVo>)request.getAttribute("pageVo");
    String str = request.getAttribute("str").toString();
// 当前页
    int curPage = pageVo.getPage();
// 上一页
    int prePage = curPage>=2?curPage-1:1;
// 总页数
    int maxPage = pageVo.getTotal();
// 下一页
    int nextPage = curPage+1;

    pageContext.setAttribute("str", str);
    pageContext.setAttribute("pageVo", pageVo);
    pageContext.setAttribute("prePage", prePage);
    pageContext.setAttribute("nextPage", nextPage);
    pageContext.setAttribute("maxPage", maxPage);
%>

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Jack's Bookshop</title>
    <!-- 导入资源 -->
    <%@ include file="resource.jsp"%>
</head>
<body>
<%@ include file="header.jsp"%>
<%--<h1>Book Search</h1>--%>
<%--<form class="d-flex" role="search" action="BookSearchServlet" method="post">--%>
<%--    <input name="str" value="${str}" class="form-control me-2" type="search" placeholder="Search" aria-label="Search">--%>
<%--    <button class="btn btn-outline-success" type="submit">Search</button>--%>
<%--</form>--%>

<div class="container" style="margin: 24px auto;">
    <div class="row">
        <div  id="main" class="col-md-12">
            <c:forEach var="book" items="${pageScope.pageVo.list}" varStatus="status">
                <div class="card mb-3">
                    <div class="row g-0">
                        <div class="col-md-4">
                            <img src="assets/images/books/${book.image_url}"
                                 class="img-fluid rounded-start" alt="...">
                        </div>
                        <div class="col-md-8">
                            <div class="card-body">
                                <h5 class="card-title">${book.title}</h5>
                                <p>
                                    <strong>Category:</strong> <a href="book.jsp?c2=${book.c2_id}&page=1&size=2">${book.c2_text}</a> >> <a
                                        href="category.jsp">${book.c1_text}</a>
                                </p>
                                <p>
                                    <strong>Score:</strong>
                                    <c:forEach begin="1" end="${book.score}" var="i">
                                        <i class="bi bi-star-fill"></i>
                                    </c:forEach>
                                </p>
                                <p>
                                    <strong>Price: $${book.price}</strong>
                                </p>
                                <p style="overflow: hidden;display: -webkit-box;-webkit-line-clamp: 4;-webkit-box-orient: vertical;">
                                    <strong>Description:</strong>${book.description}
                                </p>
                                <p>
                                    <a href="book-one.jsp?id=${book.id}" class="btn btn-primary">Go
                                        to View</a>
                                </p>
                                <p class="card-text">
                                    <small class="text-muted">Last updated 3 mins ago</small>
                                </p>
                            </div>
                        </div>
                    </div>
                </div>
            </c:forEach>
        </div>
    </div>
</div>

<nav aria-label="Page navigation example">
    <ul class="pagination justify-content-center">
        <li class="page-item <c:if test="${pageVo.page==1}">disabled</c:if>"><a class="page-link" href="BookSearchServlet?str=${str}&page=${prePage}&size=${pageVo.size}">&lt; Previous</a></li>
        <li class="page-item <c:if test="${pageVo.page==1}">disabled</c:if>">
            <a class="page-link" href="BookSearchServlet?str=${str}&page=1&size=${pageVo.size}">Page 1</a>
        </li>
        <li class="page-item"><a href="#" class="page-link active">Now:${pageVo.page}</a></li>
        <li class="page-item ${pageVo.page<pageVo.total?"":"disabled"}">
            <a class="page-link" href="BookSearchServlet?str=${str}&page=${maxPage}&size=${pageVo.size}">End:${maxPage}</a>
        </li>
        <li class="page-item"><a class='page-link ${pageVo.page<pageVo.total?"":"disabled"}' href="BookSearchServlet?str=${str}&page=${nextPage}&size=${pageVo.size}">Next &gt;</a></li>
    </ul>
</nav>
<%@ include file="footer.jsp"%>
</body>
</html>
